<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $.post("http://localhost:8080/AJAX-JSON/ajaxServlet",{
                    username:"cola",
                    password:"123456"
                },
                function(data,status){
                    alert("用户名: \n" + data + "\n状态: " + status);
                    var jsonArray = JSON.parse(data);
                    console.log(jsonArray);
                    for(var i=0;i<jsonArray.length;i++)
                    {
                        console.log(jsonArray[0].username);
                        console.log(jsonArray[0].password);
                    }
                });
        });
    });

    // var xhttp;
    // if (window.XMLHttpRequest) {
    //     xhttp = new XMLHttpRequest();
    // } else {
    //     // code for IE6, IE5
    //     xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    // }
    // xhttp.open("GET", "http://localhost:8080/AJAX-JSON/ajaxServlet", true);
    // xhttp.send();
    //
    //     xhttp.onreadystatechange = function() {
    //         if (this.readyState == 4 && this.status == 200) {
    //                 alert(this.responseText);
    //         }
    //
    // }
</script>

<button>发送一个 HTTP POST 请求页面并获取返回内容</button>

</body>
</html>